<template>
  <!-- 御剑乘风来,除魔天地间! -->
  <div>
    <el-cascader
      v-model="argument"
      :options="categoriesData"
      :props="propsP"
      @change="handleChange"
    ></el-cascader>
    {{activeName}}
  </div>
</template>
           
<script>
import { categoriesList, paramsList } from "@/api";
export default {
  props: ["propsP", "activeName"],
  data() {
    return {
      argument: [],
      categoriesData: [],
      paramList:[]
    };
  },
  methods: {
    async getCategoriesList() {
      var { data: res } = await categoriesList({ type: [3] });
      this.categoriesData = res.data;
    },

    async handleChange() {
      //选择分类获取参数
      if (this.argument.length !== 3) {
        return (this.argument = []);
      }
      //   this.categoriesId = this.argument[this.argument.length - 1];
      var { data: res } = await paramsList({
        id: this.argument[this.argument.length - 1],
        sel: this.activeName
      });
      if (res.meta.status !== 200)
        return this.$message.error("获取动态参数失败！");

      res.data.forEach(item => {
        item.inputVisible = false;
        item.inputValue = "";
      });
    //   console.log(res.data, 111);
        //把attr_vals字符串转换为数组类型
        this.paramList = res.data;
        this.paramList.forEach(item => {
         item.attr_vals =  item.attr_vals ? (item.attr_vals.split(" ")) : [];
          
        });

        console.log(this.paramList, 95);
      this.$emit("cascaderFun", {
        argument: this.argument,
        categoriesData: this.categoriesData,
        paramList: this.paramList
      });
    }
  },
  //生命周期
  created() {
    this.getCategoriesList();
  },
  //侦听器
  watch: {
    activeName() {
    //   console.log("你根改了我的内容");
      this.handleChange();
    }
  }
};
</script>
<style scoped>
</style>